<?php
namespace app\home\controller;
use think\Controller;
use app\home\model\Freedbook as FreedbookModel;
class Freedbook extends controller
{
	public function index()
	{
		if (!isset($_SERVER['HTTP_REFERER']) || stripos($_SERVER['HTTP_REFERER'], 'localhost')) {
			return json(array('status'=>0, 'info'=>'没有权限'));
		} else {
			$CustomerModel = new FreedbookModel();
			if($this->request->isPost()){
				$data = input('post.');
					$rules = array(	 
						array('mianji', 'require', '请输入房屋面积'),
						array('contacts', 'require', '请输入姓名'),
						array('mobile', 'require', '请输入手机号'),
						
					);
					$phone=preg_match("/^1[3456789]\d{9}$/",$data['mobile']);
					if(!$phone){
						return json(array('status'=>1, 'info'=>'请输入正确的手机号！'));
					}
					$result['contacts'] = $data['contacts'];//客户名称
					$result['mobile'] = $data['mobile'];//客户电话
					$result['contacts'] = $data['contacts'];
					$result['create_time'] = date("Y-m-d H:i:s",time());
					header("Access-Control-Allow-Headers: x-requested-with,content-type");
					header('Access-Control-Allow-Methods: OPTIONS,POST,GET');
					if($CustomerModel->add($result)){
						return json(array('status'=>1, 'info'=>'信息提交成功，请保持电话畅通！'));
					}else{
						return json(array('status'=>0, 'info'=>'失败，请联系管理员'));
					}
			}
		}
    }
}